package com.syq.service.impl;

import com.syq.dao.SysUserOnlineMapper;
import com.syq.pojo.SysUserOnline;
import com.syq.service.SysUserOnlineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Sun Yueqi
 * @version 1.00
 * @time 2022/5/26 20:26
 */
@Service
public class SysUserOnlineServiceImpl implements SysUserOnlineService {
    private SysUserOnlineMapper userOnlineMapper;

    @Autowired
    public void setUserOnlineMapper(SysUserOnlineMapper userOnlineMapper) {
        this.userOnlineMapper = userOnlineMapper;
    }

    @Override
    public void addOrUpdateOnline(SysUserOnline sysUserOnline) {
        //查询当前用户的数据是不是存在
        String sessionId = userOnlineMapper.findOnlineDataByUsername(sysUserOnline.getLoginName());
        if (sessionId != null) {
            //有数据先删除
            userOnlineMapper.deleteByUsername(sysUserOnline.getLoginName());
        }
        //添加数据
        userOnlineMapper.addOnlineData(sysUserOnline);

    }

}
